(function (vc, vm) {

    vc.extends({
        data: {
            editCommunityRecommendInfo: {
                crId: '',
                communityName: '',
                shopName: '',
                recommendType: '',
                logo: '',
                prodName: '',
                price: '',
                url: '',

            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('editCommunityRecommend', 'openEditCommunityRecommendModal', function (_params) {
                $that.refreshEditCommunityRecommendInfo();
                $('#editCommunityRecommendModel').modal('show');
                vc.copyObject(_params, $that.editCommunityRecommendInfo);
                let _photos = [];
                _photos.push(_params.logo);
                vc.emit('editCommunityRecommend', 'uploadImageUrl', 'notifyPhotos', _photos);

            });
            vc.on("editCommunityRecommend", "notifyUploadCoverImage", function (_param) {
                if (_param) {
                    $that.editCommunityRecommendInfo.logo = _param[0].url;
                } else {
                    $that.editCommunityRecommendInfo.logo = '';
                }
            });
        },
        methods: {
            editCommunityRecommendValidate: function () {
                return vc.validate.validate({
                    editCommunityRecommendInfo: $that.editCommunityRecommendInfo
                }, {
                    
                    'editCommunityRecommendInfo.logo': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "推荐logo不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "512",
                            errInfo: "推荐logo不能超过512"
                        },
                    ],
                    'editCommunityRecommendInfo.prodName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "商品名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "256",
                            errInfo: "商品名称不能超过256"
                        },
                    ],
                    'editCommunityRecommendInfo.price': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "价格不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "10",
                            errInfo: "价格不能超过10"
                        },
                    ],
                   
                    'editCommunityRecommendInfo.crId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "编号不能为空"
                        }]

                });
            },
            editCommunityRecommend: function () {
                if (!$that.editCommunityRecommendValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/recommend.updateCommunityRecommend',
                    JSON.stringify($that.editCommunityRecommendInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editCommunityRecommendModel').modal('hide');
                            vc.emit('communityRecommend', 'listCommunityRecommend', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditCommunityRecommendInfo: function () {
                $that.editCommunityRecommendInfo = {
                    crId: '',
                    communityName: '',
                    shopName: '',
                    recommendType: '',
                    logo: '',
                    prodName: '',
                    price: '',
                    url: '',
                }
            }
        }
    });

})(window.vc, window.$that);
